package com.xhhuang.controller;

import com.xhhuang.form.ProductForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;

/**
 * Created by xhhuang on 2017/12/17.
 */
@Controller
public class ProductController {
  private static final Logger logger = LoggerFactory.getLogger(ProductController.class);

  @RequestMapping(value = "/input-product")
  public String inputProduct(){
    logger.info("inputProduct called.");

    return "ProductForm";
  }

  @RequestMapping(value = "/save-product")
  public String saveProduct(ProductForm productForm, Model model){
    logger.info("saveProoduct called.");

    Product product = new Product();
    product.setName(productForm.getName());
    product.setDescprition(productForm.getDescription());
    product.setPrice(new BigDecimal(productForm.getPrice()));

    model.addAttribute("product", product);

    return "ProductDetails";
  }


}
